package com.villaday.idf.adapter;

import android.content.Context;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.text.Html;
import android.view.View;
import android.widget.TextView;

import com.villaday.idf.R;
import com.villaday.idf.base.AbsRecyclerViewAdapter;
import com.villaday.idf.base.OnAdapterCallbackListener;
import com.villaday.idf.model.MYHousesEntity;
import com.villaday.idf.model.SheBeiEntity;
import com.villaday.idf.model.TopicEntity;
import com.villaday.idf.util.PhoneUtil;

/**
 * 首页动态列表
 */

public class HomeFacilityAdapter extends AbsRecyclerViewAdapter<SheBeiEntity> {
    private OnAdapterCallbackListener onAdapterCallbackListener;
    private View.OnClickListener onClickListener;
/*
    private final String roleType;
*/

    public HomeFacilityAdapter(Context context) {
        super(context, R.layout.item_homefacility, R.layout.item_page_loading,
                R.layout.item_page_bottom);

       /* RefreshtokenEntity.BodyBean roleInfo =
                SharedPreferencesUtil.getRoleInfo(context);
        roleType = roleInfo.getMember().getType();*/

    }


    @Override
    public void onBindHolder(AbsRecyclerViewAdapter.RecyclerViewHolder holder, SheBeiEntity d, int position) {
       /* holder.bindSimpleDraweeView(R.id.sdv,d.getImageURL())
                .bindTextView(R.id.tv_title,d.getDescription())
                .bindTextView(R.id.detail,d.getLocation().getProvince()+"·"+d.getLocation().getCity())
                .bindTextViewWithHtml(R.id.tv_price,"&yen;" + (d.getOriginalPrice() == 0 ? "0.00" : PhoneUtil.handleBalance(d.getOriginalPrice() / 100.0 + "", 0)));*/



        TextView view = (TextView) holder.getView(R.id.tv_icon);
       /* Drawable drawableLeft = context.getResources().getDrawable(
                R.drawable.ic_launcher);

        view.setCompoundDrawablesWithIntrinsicBounds(
                null, drawableLeft,null, null);
        view.setCompoundDrawablePadding(4);*/


        Typeface iconfont = Typeface.createFromAsset(context.getAssets(), "iconfont.ttf");
        view.setTypeface(iconfont);
        if (d.getType() == 1) {
            view.setText("");
            holder.bindTextView(R.id.tv_name,  "");

        } else {
            view.setText(Html.fromHtml(d.getIcon()));
            holder.bindTextView(R.id.tv_name, d.getName() + "");

        }

        //getImageResourceId(d.getIconClass())


    }

    public int getImageResourceId(String name) {
        R.string string = new R.string();
        //默认的id
        int resId = 0x7f09002b;
        try {
            //根据字符串字段名，取字段//根据资源的ID的变量名获得Field的对象,使用反射机制来实现的
            java.lang.reflect.Field field = R.string.class.getField(name);
            //取值
            resId = (Integer) field.get(string);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return resId;
    }
}
